-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TYP: Annotate groupby/ops.py #32921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TYP: Annotate groupby/ops.py #32921
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Generally if you can add subscripts for List / Callable would be ideal
Also the np.ndarray usage might be suspect. It resolves to Any
right now so will pass the checker, but we might accept more than just ndarrays in those methods
Co-Authored-By: William Ayd <william.ayd@icloud.com>
merge master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one comment + Brock comment; otherwise lgtm
pandas/core/groupby/ops.py
Outdated
@@ -828,11 +832,11 @@ def result_index(self): | |||
return self.binlabels | |||
|
|||
@property | |||
def levels(self): | |||
def levels(self) -> List: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think List[int] here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this perhaps be List[Index] since this is [self.binlabels]? It looks like at line 733 we call ensure_index(binlabels) and below here we call binlabels.name. The docstring is weird though ("binlabels : the label list")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you rebase on master. just merged a change by @simonjayhawkins , see here: #33456 for callables
@@ -916,7 +918,7 @@ def _chop(self, sdata: Series, slice_obj: slice) -> Series: | |||
|
|||
|
|||
class FrameSplitter(DataSplitter): | |||
def fast_apply(self, f, sdata: FrameOrSeries, names): | |||
def fast_apply(self, f: F, sdata: FrameOrSeries, names): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we say anything about names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly List[Label] but I'm not sure
LGTM. @simonjayhawkins are we at a point where mypy would tell us if anything here were incorrect? |
using the word 'incorrect' I think would only apply if we have 100% static typing. I don't think we have an appetite for that (achieving consensus in the pandas team). By 100% static typing, I mean 0% dynamic types. That means nothing resolves to Any. That includes all imports and cython code. It also includes code patterns that create classes, methods and attributes etc dynamically. We have alot of dynamic code. Mypy tells us if the types added here are 'consistent' with the other types already added. The more types added and the more refined the types the better the 'correctness'. Again, there does not seem to be an appetite for some patterns that refine types or workflows that expedite the addition of types. IMO with typing, 'Job done is better than perfect'. Simply put, the more types added overall, the more confidence we can get for refactoring, enhancement PRs etc. so PRs that add types, keep mypy green and are not obviously wrong get a thumbs up from me. partial typed function signatures are better than none. unparameterized generics are more refined than Any. If we did want to enforce this we would use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
can you merge master, ping on green. |
@jreback Merged and green |
* TYP: Annotate groupby/ops.py * Blacken * Update pandas/core/groupby/ops.py Co-Authored-By: William Ayd <william.ayd@icloud.com> * Use ellipsis * List -> List[Index] * Specify Callable types * More Callable subscripts * Update * No ArrayLike * Import * Update * Use F * Lint Co-authored-by: William Ayd <william.ayd@icloud.com>
Adding a few type annotations to this file. I think the
values
arguments here should bendarrays
but am not positive.